package com.bibrApp.difu.actvity.account_info_mvp;


import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.TextView;

import com.bibrApp.difu.Config;
import com.bibrApp.difu.DfApp;
import com.bibrApp.difu.R;
import com.bibrApp.difu.Response.LoginResponseBody;
import com.bibrApp.difu.actvity.login_mvp.LoginActivity;
import com.bibrApp.difu.base.BaseActivity;
import com.bibrApp.difu.utils.BiBrShare;
import com.bibrApp.difu.utils.IntentUtil;
import com.bibrApp.difu.utils.ShareUtils;
import com.bibrApp.difu.utils.ToastUtils;
import com.gyf.barlibrary.ImmersionBar;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.OnClick;

public class AccountInfoActivity extends BaseActivity<AccountInfoPresenter> implements IAccountInfoView {

    private ImmersionBar mImmersionBar;
    private Context mContext;
    @BindView(R.id.account_uid)
    TextView account_uid;
    @BindView(R.id.account_phone)
    TextView account_phone;
    @BindView(R.id.account_email)
    TextView account_email;
    private ShareUtils<LoginResponseBody> biBrShare;

    @Override
    protected void initPresenter() {
        presenter = new AccountInfoPresenter(this, this);
        presenter.init();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_account_info;
    }

    @Override
    public void initView() {
        mContext = this;
        mImmersionBar = ImmersionBar.with(this);
        mImmersionBar.statusBarColor(R.color.white)
                .statusBarDarkFont(true)
                .fitsSystemWindows(true)
                .init();
        biBrShare = BiBrShare.getShare(mContext, Config.FILE_ACCOUNT);
        DfApp dfApp = (DfApp) getApplication();
        account_uid.setText(dfApp.getuId());
        LoginResponseBody loginResponseBody = dfApp.getmData();
        if(loginResponseBody != null){
            account_phone.setText(loginResponseBody.getCenterUserMain().getPhone());
            account_email.setText(loginResponseBody.getCenterUserMain().getEmail());
        }

    }


    @Override
    public void error(String msg) {
        ToastUtils.ShowToast(mContext, msg);
    }

    @Override
    public void success(String msg) {
        ToastUtils.ShowToast(mContext, msg);
        biBrShare.clearAll();

        DfApp app = (DfApp) getApplication();
        app.setuId(null);
        app.setUserId(null);
        app.setToken(null);
        app.setmData(null);
        app.setNickImage(null);
        app.setNickName(null);

        IntentUtil.toActivity(LoginActivity.class, this);
        finish();
    }

    @OnClick(R.id.return_iv)
    public void onBackClick(){
        finish();
    }

    @OnClick(R.id.login_out_btn)
    public void clickLoginOut(){
        DfApp dfApp = (DfApp) getApplication();
        presenter.loginOutP(dfApp.getUserId());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mImmersionBar != null) {
            mImmersionBar.destroy();
        }
    }

}
